package org.hackystat.devcathlon.ui.page.scoreboard;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.apache.wicket.util.tester.FormTester;
import org.apache.wicket.util.tester.WicketTester;
import org.hackystat.devcathlon.configuration.ConfigurationException;
import org.hackystat.devcathlon.engine.test.DevcathlonTestHelper;
import org.hackystat.devcathlon.ui.DevcathlonApplication;
import org.hackystat.devcathlon.ui.DevcathlonSession;
import org.hackystat.devcathlon.ui.page.login.LoginPage;
import org.junit.Test;

/**
 * Tests the ScoreBoard implementation.
 * 
 * @author Daniel Arakaki, Robin Raqueno
 */
public class TestScoreboardModel extends DevcathlonTestHelper {

    /**
     * Test get MatchesManageModel from session.
     */
    @Test
    public void testSession() {
      WicketTester tester = new WicketTester();
      tester.setupRequestAndResponse();
      DevcathlonSession devcathlonSession = new DevcathlonSession(tester.getWicketRequest());
      ScoreboardModel scoreboardModel = 
         devcathlonSession.getScoreboardSession().getScoreboardModel();
      assertNotNull("is not null", scoreboardModel);
    }
    
    /**
     * Test Scoreboard page.
     * 
     * @throws ConfigurationException Unexpected error. 
     */
    @Test
    public void testPage() throws ConfigurationException {
      WicketTester tester = new WicketTester(new DevcathlonApplication());
      tester.startPage(ScoreboardPage.class);
      tester.assertRenderedPage(LoginPage.class);
      
      FormTester formTester = tester.newFormTester("loginForm");
      formTester.setValue("user", "admin@hackystat.org");
      formTester.setValue("password", "admin@hackystat.org");
      formTester.submit();
      
      tester.assertRenderedPage(ScoreboardPage.class);
      assertNull("wicket ID form should not be found.", tester.getTagByWicketId("invitations"));
    }
}
